package com.hqq.controller;

import com.hqq.annotation.Action;
import com.hqq.annotation.Aspect;
import com.hqq.annotation.Controller;
import com.hqq.annotation.Inject;
import com.hqq.http.Data;
import com.hqq.http.Param;
import com.hqq.http.RequestMethod;
import com.hqq.http.View;
import com.hqq.proxy.AspectProxy;
import com.hqq.service.CustomerService;
import com.hqq.service.HelloService;

import java.util.HashMap;
import java.util.Map;

/**
 * HelloController
 * Created by heqianqian on 2017/7/19.
 */
@Controller
//@Aspect(value = Controller.class)
public class HelloController extends AspectProxy {

    @Inject
    private HelloService helloService;

    @Inject
    private CustomerService customerService;

    @Action(value = "/hi", method = RequestMethod.POST)
    public View params(String name) {
        helloService.sayHi(name);
        return new View("hello");
    }

    @Action("/hello")
    public View hello() {
        return new View("hello");
    }

    @Action("/json/get")
    public Data jsonGet() {
        return new Data("hello,java/get");
    }

    @Action(value = "/json/post", method = RequestMethod.POST)
    public Data jsonPost() {
        return new Data("hello,java/post");
    }

    @Action("/service")
    public View service() {
        helloService.sayHello();
        return new View("index");
    }

    @Action("/insert")
    public View insert() {
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("name", "heqianqian");
        fieldMap.put("contact", "18279199626");
        fieldMap.put("telephone", "23123");
        customerService.insertCustomer(fieldMap);
        return new View("index");
    }

    @Action("/param")
    public View param(String name) {
        //Map<String, Object> param_map = param.getPARAM_MAP();
        //for (Map.Entry<String, Object> p : param_map.entrySet()) {
        //    System.out.println(p.getKey() + " " + p.getValue());
        //}
        System.out.println("name=" + name);
        return new View("index");
    }
}
